<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
use app\common\model\AdminAdmin;
class SchoolCustomerWorker extends Model
{
    use SoftDelete;
     protected $deleteTime = "delete_time";
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        $nickname = input('get.nickname', '');
        $admin = session('admin');
        $where[] = ['top_id', '=', $admin['id']];
        if ($nickname) {
            $where[] = ['nickname', 'like', '%'.$nickname.'%'];
        }
        $list = AdminAdmin::with([
            'get_school' => function($a) {
                $a->field('id,school_name');
            }
        ])->order('id','desc')->where($where)->paginate($limit)->each(function (&$item) use ($admin){
//            $time = strtotime(date('Y-m-d').' 23:59:59');
            $start = new \DateTime();
            $start->modify('-10 days');
            $start = $start->format('Y-m-d');
            $item['count'] = RecruitCustomerPhone::where('admin_id',$item['id'])
                ->whereTime('create_time', 'between', [$start,date('Y-m-d 23:59:59')])
                ->count();
            $item['custom'] = RecruitCustomer::where('admin_id',$item['id'])
                ->whereTime('create_time', 'between', [$start,date('Y-m-d 23:59:59')])
                ->count();
//            dd(RecruitCustomer::getlastsql());
        });
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }


}
